package com.bulls.demo.hrmsdemo.action;

import java.util.ArrayList;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import com.bulls.demo.hrmsdemo.form.EmployeeForm;
import com.bulls.demo.hrmsdemo.service.ListService;
import com.bulls.demo.hrmsdemo.utils.Utilities;

public class ListAction extends Action{
	
	public ActionForward execute(ActionMapping actionMapping,ActionForm actionForm,
			 HttpServletRequest request,HttpServletResponse response)throws Exception{
		System.out.println("action------------>");
		String forwardPath = "failure";
		EmployeeForm form = (EmployeeForm)actionForm;
		String command = request.getParameter("cmd");
		System.out.println("cmd"+command);
		if("EmployeeList".equals(command)){
			forwardPath = executeEmployeeList(request,response,form);
		}
		return actionMapping.findForward(forwardPath);
	}

	private String executeEmployeeList(HttpServletRequest request,
			HttpServletResponse response, EmployeeForm form) {
		// TODO Auto-generated method stub
		ArrayList employeeList = getListService().getEmployeeList();
		String responseString = Utilities.getResponseString(employeeList);
		request.setAttribute("responseForList", responseString);
		return "open";
	}

	private String executeOpen(HttpServletRequest request,
			HttpServletResponse response, EmployeeForm form) {
		// TODO Auto-generated method stub
		return "open";
	}

	private ListService getListService(){
		ListService listService = new ListService();
		return listService;
	}

}
